while getopts ":u:f:n:v:q:" opt
do
    case $opt in
        u)
        PRO_URL=$OPTARG
        echo -e "\033[40;37m 您提供的模块地址:$PRO_URL\033[0m"
        ;;
        f)
        FORCE_START=$OPTARG
        echo -e "\033[40;37m 您输入的是否强制启动:$FORCE_START\033[0m"
        ;;
        n)
        ENCRY_NAME=$OPTARG
        echo -e "\033[40;37m 您输入的备份路径:$ENCRY_NAME\033[0m"
        ;;
        v)
        TAOS_VERSION=$OPTARG
        echo -e "\033[40;37m 您输入的回滚版本:$TAOS_VERSION\033[0m"
        ;;
        q)
        QUICK_STYLE=$OPTARG
        echo -e "\033[40;37m 您输入的快速方式:$TAOS_VERSION\033[0m"
        ;;
        ?)
        echo -e "\033[40;37m 未知参数,你可以这样使用 : sh pub.sh -u 123 -btrue -nhello -v3.0.1.3\033[0m"
        exit 1;;
    esac
done
DIR=$(cd "$(dirname "$0")";pwd)
sudo cp -rvf ${DIR}/toolbox/guardDogs/* /opt/apexapp/.local/bin
shell_sc=$(ls -1 ${DIR}/toolbox/guardDogs | grep -E ".sh$")
for ss in ${shell_sc[@]}
do
  sudo chmod +x /opt/apexapp/.local/bin/$ss
done
###########################health###########################
sudo cat /var/spool/cron/yapai | grep health
if [[ $? -eq 1 ]]
then
  sudo sed -i '$a\*/7 * * * * /opt/apexapp/.local/bin/check_health_on_nacos.sh >> /opt/apexapp/logs/health_check.log 2>&1' /var/spool/cron/yapai
fi
###########################ypcron###########################
sudo cat /var/spool/cron/yapai | grep ypcron
if [[ $? -eq 1 ]]
then
  sudo sed -i '$a\*/5 * * * * /opt/apexapp/.local/bin/ypcron >> /opt/apexapp/logs/cronlog.log 2>&1' /var/spool/cron/yapai
fi
###########################td_memory###########################
sudo cat /var/spool/cron/yapai | grep check_td_memory
if [[ $? -eq 1 ]]
then
  sudo sed -i '$a\0 1 * * * /opt/apexapp/.local/bin/check_td_memory.sh >> /opt/apexapp/logs/check_td_memory.log 2>&1' /var/spool/cron/yapai
fi
###########################clean_log###########################
sudo cat /var/spool/cron/yapai | grep auto_clean_log
if [[ $? -eq 1 ]]
then
  sudo sed -i '$a\0 1 * * * /opt/apexapp/.local/bin/auto_clean_log.sh >> /opt/apexapp/logs/auto_clean_log.log 2>&1' /var/spool/cron/yapai
fi
tar -zxvf ${DIR}/jq.tar.gz -C ${DIR}/
sh ${DIR}/jq/install.sh
# url=$(printf $PRO_URL | base64 -d)
# simple_url=${url%%\?*}
# jar_name=${simple_url##*/}

# wget -O /opt/apexapp/services/uip/${jar_name} $url

cp -rvf ${DIR}/projects/* /opt/apexapp/services
if [[ $FORCE_START == "true" ]]
then
pros=$(ls -1l ${DIR}/projects/ | grep -E "^d")
for pro in ${pros[@]}
do
  ypstart -r 1 $pro
done
fi
